package com.mnnu.mapper;

import com.mnnu.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface EmpMapper {

    /*
    //查询总记录数
    @Select("select count(*) from emp")
    Long count();
    //分页查询获取数据
    @Select("select * from emp limit #{index}, #{pageSize}")
    List<Emp> page(Integer index, Integer pageSize);
    */

    /**
     * pagehelper分页查询员工信息
     * @return
     */
    //@Select("select * from emp")
    List<Emp> page(String name, Short gender, LocalDate begin, LocalDate end);

    /**
     * 删除数据
     * @param ids
     */
    void delete(List<Integer> ids);


    /**
     * 新增数据
     * @param emp
     */
    @Insert("insert into emp(username, name, gender, image, job, entrydate, dept_id, create_time, update_time)" +
            " values(#{username}, #{name}, #{gender}, #{image}, #{job}, #{entrydate}, #{deptId}, #{createTime}, #{updateTime})")
    void add(Emp emp);

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Select("select * from emp where id = #{id}")
    Emp getById(Integer id);

    /**
     * 更改员工信息
     * @param emp
     */
    void update(Emp emp);

    /**
     * 通过username和password查询员工信息
     * @param emp
     * @return
     */
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp getByUsernameAndPassword(Emp emp);

    /**
     * 根据deptId删除员工数据
     * @param deptId
     */
    @Delete("delete from emp where dept_id = #{deptId}")
    void deleteByDeptId(int deptId);
}
